//
//  GKZYPostBarDetailsTableViewCell.m
//  GKZYAid
//
//  Created by lanou3g on 16/3/14.
//  Copyright © 2016年 GKZYAid. All rights reserved.
//

#import "GKZYPostBarDetailsTableViewCell.h"

@implementation GKZYPostBarDetailsTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier viewRow:(NSInteger)row
{
    self.viewRow = row;
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllViews];
    }
    return self;
}

- (void)addAllViews
{
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.imageUserHeader = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, self.frame.size.width * 0.06, self.frame.size.width * 0.2, self.frame.size.width * 0.2)];
    self.imageUserHeader.backgroundColor = [UIColor yellowColor];
    self.imageUserHeader.layer.masksToBounds = YES;
    self.imageUserHeader.layer.cornerRadius = self.imageUserHeader.frame.size.width * 0.5;
    [self addSubview:self.imageUserHeader];
    
    self.labelUserName = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imageUserHeader.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.11, self.frame.size.width * 0.6, self.frame.size.width * 0.1)];
    [self addSubview:self.labelUserName];
    
    self.labelContent = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.imageUserHeader.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.labelContent.frame.size.height)];
    self.labelContent.numberOfLines = 0;
    [self addSubview:self.labelContent];
    
    if (self.viewRow == 1) {
        
        self.detailsImageView1 = [[DetailsImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.labelContent.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29)];
        [self addSubview:self.detailsImageView1];
        
    }else if (self.viewRow == 2){
        
        self.detailsImageView1 = [[DetailsImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.labelContent.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29)];
        [self addSubview:self.detailsImageView1];
        self.detailsImageView2 = [[DetailsImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.detailsImageView1.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29)];
        [self addSubview:self.detailsImageView2];
        
    }else if (self.viewRow == 3){
        self.detailsImageView1 = [[DetailsImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.labelContent.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29)];
        [self addSubview:self.detailsImageView1];
        self.detailsImageView2 = [[DetailsImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.detailsImageView1.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29)];
        [self addSubview:self.detailsImageView2];
        self.detailsImageView3 = [[DetailsImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.detailsImageView2.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29)];
        [self addSubview:self.detailsImageView3];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imageUserHeader.frame = CGRectMake(self.frame.size.width * 0.05, self.frame.size.width * 0.06, self.frame.size.width * 0.2, self.frame.size.width * 0.2);
    self.imageUserHeader.layer.cornerRadius = self.imageUserHeader.frame.size.width * 0.5;
    
    self.labelUserName.frame = CGRectMake(CGRectGetMaxX(self.imageUserHeader.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.11, self.frame.size.width * 0.6, self.frame.size.width * 0.1);
    
    self.labelContent.frame = CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.imageUserHeader.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.labelContent.frame.size.height);
    
    self.detailsImageView1.frame = CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.labelContent.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29);
    
    self.detailsImageView2.frame = CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.detailsImageView1.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29);
    
    self.detailsImageView3.frame = CGRectMake(self.frame.size.width * 0.05, CGRectGetMaxY(self.detailsImageView2.frame) + self.frame.size.width * 0.05, self.frame.size.width * 0.9, self.frame.size.width * 0.29);
}

- (CGFloat)labelHeight:(NSString *)text withFont:(CGFloat)font
{
    CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width * 0.98, 1000);
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:font]};
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height  + self.frame.size.width * 0.06;
}

- (CGFloat)viewImageHeight
{
    if (self.viewRow == 1) {
        return self.frame.size.width * 0.45;
    }else if (self.viewRow == 2){
        return self.frame.size.width * 0.75;
    }else if (self.viewRow == 3){
        return self.frame.size.width * 1.15;
    }
    return 0;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
